<?php
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use app\common\model\InfoSchoolModel;
/**
 * 学校主页
 */
class InfoSchoolController extends AdminBaseController
{
	public function index(){
		$param = $this->request->param();
		$data = InfoSchoolModel::where('content_status',2)->order('info_school_id desc')->paginate(20,false,['query'=>$param]);
		$this->assign('data',$data);
		return $this->fetch();
	}
	
	public function add(){
		return $this->fetch();
	}

	public function toAdd(InfoSchoolModel $InfoSchool){
		$param = $this->request->param();
		$param['post']['content_status'] = 2;
		$rs = $InfoSchool->save($param['post']);
		if($rs){
			$this->success('上传成功','index');
		}else{
			$this->error('上传失败');
		}
	}
	//编辑
	public function edit(){
		$param = $this->request->param();
		$data = InfoSchoolModel::get($param['id']);
		$this->assign('data',$data);
		return $this->fetch();
	}
	//提交编辑
	public function toEdit(InfoSchoolModel $InfoSchool){
		$param = $this->request->param();
		$rs = $InfoSchool->save($param['post'],['info_school_id'=>$param['info_school_id']]);
		if($rs){
			$this->success('编辑成功','index');
		}else{
			$this->error('编辑失败');
		}

	}

	public function set(){
		$param = $this->request->param();
		$rs = InfoSchoolModel::where('info_school_id',$param['id'])->update(['status'=>$param['status']]);
		if($rs){
			$this->success('操作成功');
		}else{
			$this->error('操作失败');
		}
	}
	//添加预览
	public function addContent(InfoSchoolModel $InfoSchool){
		$param = $this->request->param();
		$rs = $InfoSchool->save($param);
		if($rs){
			$this->success('上传成功','',$InfoSchool->info_school_id);
		}else{
			$this->error('上传失败');
		}
	}
	
	public function look(){
		$param = $this->request->param();
		$data = InfoSchoolModel::get($param['id']);
		$this->assign('data',$data);
		return $this->fetch();
	}
}
